package com.muyu.danmo.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.danmo.domain.DanmoPortfolioCollection;
import com.muyu.danmo.service.IDanmoPortfolioCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 作品集收藏Controller
 * 
 * @author yangle
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/danmoPortfolioCollection")
public class DanmoPortfolioCollectionController extends BaseController
{
    @Autowired
    private IDanmoPortfolioCollectionService danmoPortfolioCollectionService;

    /**
     * 查询作品集收藏列表
     */
//    @RequiresPermissions("system:danmoPortfolioCollection:list")
    @GetMapping("/list")
    public Result<TableDataInfo<DanmoPortfolioCollection>> list(DanmoPortfolioCollection danmoPortfolioCollection)
    {
        startPage();
        List<DanmoPortfolioCollection> list = danmoPortfolioCollectionService.selectDanmoPortfolioCollectionList(danmoPortfolioCollection);
        return getDataTable(list);
    }

    /**
     * 导出作品集收藏列表
     */
//    @RequiresPermissions("system:danmoPortfolioCollection:export")
    @Log(title = "作品集收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoPortfolioCollection danmoPortfolioCollection)
    {
        List<DanmoPortfolioCollection> list = danmoPortfolioCollectionService.selectDanmoPortfolioCollectionList(danmoPortfolioCollection);
        ExcelUtil<DanmoPortfolioCollection> util = new ExcelUtil<DanmoPortfolioCollection>(DanmoPortfolioCollection.class);
        util.exportExcel(response, list, "作品集收藏数据");
    }

    /**
     * 获取作品集收藏详细信息
     */
//    @RequiresPermissions("system:danmoPortfolioCollection:query")
    @GetMapping(value = "/{collectionId}")
    public Result getInfo(@PathVariable("collectionId") Long collectionId)
    {
        return success(danmoPortfolioCollectionService.selectDanmoPortfolioCollectionByCollectionId(collectionId));
    }

    /**
     * 新增作品集收藏
     */
//    @RequiresPermissions("system:danmoPortfolioCollection:add")
    @Log(title = "作品集收藏", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result add(@RequestBody DanmoPortfolioCollection danmoPortfolioCollection)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser==null){
            return Result.notLoggedIn("请登录");
        }
        danmoPortfolioCollection.setUserId(loginUser.getUserid());
        return danmoPortfolioCollectionService.insertDanmoPortfolioCollection(danmoPortfolioCollection);
    }

    /**
     * 修改作品集收藏
     */
//    @RequiresPermissions("system:danmoPortfolioCollection:edit")
    @Log(title = "作品集收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoPortfolioCollection danmoPortfolioCollection)
    {
        return danmoPortfolioCollectionService.updateDanmoPortfolioCollection(danmoPortfolioCollection);
    }

    /**
     * 删除作品集收藏
     */
//    @RequiresPermissions("system:danmoPortfolioCollection:remove")
    @Log(title = "作品集收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{collectionIds}")
    public Result remove(@PathVariable Long[] collectionIds)
    {
        return danmoPortfolioCollectionService.deleteDanmoPortfolioCollectionByCollectionIds(collectionIds);
    }
}
